﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;


/*
 * First created by chenchao (Tongsui) in 2020/6/11
 * 
 * This file defines the interface for Data Access Layer (DAL)
 * 
 * 1. It provides CURD method for operating data persistence;
 * 
 */

namespace iS3.DAL
{
    public interface IDataContext<T> where T:DGBase,new()
    {
        bool InitDatabase();
        bool InitTable(ExternalStorageConfig config=null);
        bool UpdateTable_add(DGPropertyStruct model);
        bool BatchUpdateTable_add(List<DGPropertyStruct> models);
        bool UpdateTable_modify(DGPropertyStruct oldOne,DGPropertyStruct newOne);
        bool BatchUpdateTable_modify(List<DGPropertyStruct> oldOnes, List<DGPropertyStruct> newOnes);
        bool UpdateTable_delete(DGPropertyStruct model);
        bool BatchUpdateTable_delete(List<DGPropertyStruct> models);
        T Create(T model, ExternalStorageConfig config = null);
        List<T> BatchCreate(List<T> models, ExternalStorageConfig config = null);
        T Update(T model, ExternalStorageConfig config = null);
        T Update(T model, string propertyName, ExternalStorageConfig config = null);
        T Update(T model, List<string> propertyNames, ExternalStorageConfig config = null);
        List<T> BatchUpdate(List<T> models, ExternalStorageConfig config = null);
        T Retrieve(long id, ExternalStorageConfig config = null);
        List<T> Query(string where=null,string order=null, ExternalStorageConfig config = null);
        List<T> QueryByPage(int pageSize, int currentPage, string order ,string where = null, ExternalStorageConfig config = null);
        //List<T> RetrieveList(string dataset=null);
        //List<T> RetrieveByPage(int pageSize, int currentPage);
        int Delete(long id, ExternalStorageConfig config = null);
        int BatchDelete(List<long> ids, ExternalStorageConfig config = null);
        int DeleteRange(string where = null, ExternalStorageConfig config = null);
        int Count( string where=null,ExternalStorageConfig config = null);

    }
}
